package com.liuxia8.part7.innerClass;

/**
 * Created by weng.junjie on 2017/2/24.
 */
public class EventSet {
    private Event[] events = new Event[10];
    private int index = 0;
    private int next = 0;

    public void add(Event e) {
        if (index >= events.length) {
            return;
        }
        events[index++] = e;
    }

    public Event getNext() {
        boolean looped = false;
        int start = next;
        do {
            next = (next + 1) % events.length;
            if (start == next)
                looped = true;
            if ((next == (start + 1) % events.length) && looped)
                return null;
        } while (events[next] == null);
        return events[next];
    }
    public void removeCurrent(){
        events[next]=null;
    }

    public Event[] getEvents() {
        return events;
    }

    public void setEvents(Event[] events) {
        this.events = events;
    }

    public int getIndex() {
        return index;
    }

    public void setIndex(int index) {
        this.index = index;
    }

    public void setNext(int next) {
        this.next = next;
    }
}
